package net;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

class LolUser  extends Thread {
	
	Socket socket; 
	
	public LolUser(Socket socket) {
		this.socket = socket;
	} 
	
	public void send() {
		//写信息
	}

	public void run() {
		try {
			//读取客户端的消息
			InputStream is= socket.getInputStream();
			byte buf[]=new byte[1000];
			int len=0;
			while((len=is.read(buf))!=-1) {	
				String info=new String(buf,0,len);
				System.out.println("线程客户说："+info);	
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
} 

/**
   *    可以连接多个人
 * fix
 *
 */
public class TCPMulitServer {
	
	public static void main(String[] args) {
		
		//建立服务器
		int n=0;
		try {
			ServerSocket server = new ServerSocket(9090);
			System.out.println("服务器开启在9090端口");
			//等待用户连接  阻塞
			while(true) {
				Socket socket= server.accept();
				System.out.println(++n+"用户连接成功");
				LolUser user=new LolUser(socket);
				user.start();
			} 
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}

}
